import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/routers/app_routes.dart';
import 'package:flutter_changdian_football/utils/custom_constant.dart';
import 'package:flutter_changdian_football/widget/screenutil/custom_screenutil.dart';
import 'package:get/route_manager.dart';

class PactDialog {

  static void show(
    BuildContext mContext, {
      Function? confirmTap,
      Function? abolishTap
    }
  ) {
    showDialog(
      barrierDismissible: false,
      context: mContext,
      builder: (BuildContext context) {
        return WillPopScope(
          onWillPop: () async => false,
          child: ShowDialogPage(
            confirmTap: confirmTap,
            abolishTap: abolishTap
          ),
        );
      }
    );
  }

}



class ShowDialogPage extends Dialog {
  ShowDialogPage({
    this.confirmTap,
    this.abolishTap
  });

  // 确认
  final Function? confirmTap;
  final Function? abolishTap;

  @override
  Widget build(BuildContext dContext) {
    return Material(
      //创建透明层
      type: MaterialType.transparency, //透明类型
      //自定义dialog布局
      child: Center(
        child: RichText(
          text: TextSpan(
            children: [
              WidgetSpan(
                child: Container(
                  margin: EdgeInsets.symmetric(horizontal: 40.w),
                  padding: EdgeInsets.only(top: 26.w, left: 20.w, right: 20.w, bottom: 20.w),
                  width: double.infinity,
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(12.r)
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        alignment: Alignment.center,
                        child: Text('温馨提示', style: TextStyle(fontSize: 18.sp, fontWeight: FontWeight.w500, color: const Color(0xff323232)),),
                      ),

                      SizedBox(height: 20.w,),

                      Container(
                        constraints: BoxConstraints(
                          maxHeight: 300.w
                        ),
                        child: ListView(
                          padding: EdgeInsets.zero,
                          shrinkWrap: true,
                          physics: const BouncingScrollPhysics(),
                          children: [
                            SizedBox(
                              child: RichText(
                                text: TextSpan(
                                  children: [
                                    TextSpan(
                                      text: '亲爱的用户，感谢您信任并使用畅点足球！\n',
                                      style: TextStyle(fontSize: 14.sp, color: const Color(0xff242941))
                                    ),

                                    TextSpan(
                                      text: '我们依据相关法律法规要求制定了',
                                      style: TextStyle(fontSize: 14.sp, color: const Color(0xff242941))
                                    ),

                                    TextSpan(
                                      text: '《用户协议》',
                                      style: TextStyle(fontSize: 14.sp, color: const Color(0xff499360)),
                                      recognizer: TapGestureRecognizer()..onTap = () {
                                        Get.toNamed(AppRoutes.inAppWebView, parameters: {
                                          'title': '用户协议',
                                          'type': CustomConstant.PRIVACY_AGREEMENT,
                                        });
                                      }
                                    ),
                                    TextSpan(
                                      text: '和',
                                      style: TextStyle(fontSize: 14.sp, color: const Color(0xff242941))
                                    ),
                                    TextSpan(
                                      text: '《服务协议》',
                                      style: TextStyle(fontSize: 14.sp, color: const Color(0xff499360)),
                                      recognizer: TapGestureRecognizer()..onTap = () {
                                        Get.toNamed(AppRoutes.inAppWebView, parameters: {
                                          'title': '服务协议',
                                          'type': CustomConstant.TERMS_OF_SERVICE,
                                        });
                                      }
                                    ),
                                    TextSpan(
                                      text: '，请您在点击同意前务必仔细阅读并充分理解相关条款，\n',
                                      style: TextStyle(fontSize: 14.sp, color: const Color(0xff242941))
                                    ),
                                    TextSpan(
                                      text: '尤其是以加粗进行标识的重要条款，同时我们提醒您重点关注以下内容：\n',
                                      style: TextStyle(fontSize: 14.sp, color: const Color(0xff242941))
                                    ),
                                    TextSpan(
                                      text: '1.在您使用相关功能或服务时，我们可能要收集、使用或共享您的必要个人信息。\n',
                                      style: TextStyle(fontSize: 14.sp, color: const Color(0xff242941))
                                    ),
                                    TextSpan(
                                      text: '2.为保障相关功能实现与安全稳定运行的目的，我们可能会申请或使用设备的权限。\n',
                                      style: TextStyle(fontSize: 14.sp, color: const Color(0xff242941))
                                    ),
                                    TextSpan(
                                      text: '3.为保障相关功能实现与安全稳定的运行，我们可能会接入由三方提供的软件包（SDK）实现相关目的，请您知悉，\n',
                                      style: TextStyle(fontSize: 14.sp, color: const Color(0xff242941))
                                    ),
                                    TextSpan(
                                      text: '我们接入的第三方SDK也可能会申请或使用某些设备权限。\n',
                                      style: TextStyle(fontSize: 14.sp, color: const Color(0xff242941))
                                    ),
                                    TextSpan(
                                      text: '4.您可以通过我们提供的帐户注销渠道进行帐户注销。\n\n',
                                      style: TextStyle(fontSize: 14.sp, color: const Color(0xff242941))
                                    ),
                                    TextSpan(
                                      text: '以上手机的信息与权限情况请您详见《隐私条款》内容；如您对以上协议内容有疑问，您可以通过以上协议中注明的联系方式与我们取得联系。\n',
                                      style: TextStyle(fontSize: 14.sp, color: const Color(0xff242941))
                                    ),
                                    TextSpan(
                                      text: '如您同意以上协议内容，请点击“同意”并开始使用我们的产品和服务！',
                                      style: TextStyle(fontSize: 14.sp, color: const Color(0xff242941))
                                    ),
                                  ]
                                )
                              ),
                            )
                          ],
                        ),
                      ),

                      SizedBox(height: 20.w,),

                      SizedBox(
                        child: Row(
                          children: [
                            Expanded(
                              child: GestureDetector(
                                behavior: HitTestBehavior.translucent,
                                onTap: () {
                                  abolishTap?.call();
                                },
                                child: Container(
                                  padding: EdgeInsets.symmetric(vertical: 12.w),
                                  decoration: BoxDecoration(
                                    borderRadius: BorderRadius.circular(8.r),
                                    border: Border.all(
                                      width: 1.w,
                                      color: const Color(0xff999999)
                                    )
                                  ),
                                  alignment: Alignment.center,
                                  child: Text('不同意', style: TextStyle(fontSize: 14.sp, color: const Color(0xff999999), fontWeight: FontWeight.w500),),
                                ),
                              ),
                            ),
                            SizedBox(width: 18.w,),
                            Expanded(
                              child: GestureDetector(
                                behavior: HitTestBehavior.translucent,
                                onTap: () {
                                  confirmTap?.call();
                                },
                                child: Container(
                                  padding: EdgeInsets.symmetric(vertical: 12.w),
                                  decoration: BoxDecoration(
                                    color: const Color(0xff499360),
                                    borderRadius: BorderRadius.circular(8.r),
                                    border: Border.all(
                                      width: 1.w,
                                      color: const Color(0xff499360)
                                    )
                                  ),
                                  alignment: Alignment.center,
                                  child: Text('同意', style: TextStyle(fontSize: 14.sp, color: Colors.white, fontWeight: FontWeight.w500),),
                                ),
                              ),
                            )
                          ],
                        ),
                      ),
                    ],
                  ),
                )
              ),
            ]
          ),
        ),
      )
    );
  }
}

